package com.leetcode.LC;

import java.util.TreeSet;

public class LC671 {

    TreeSet<Integer> set = new TreeSet<>();

    public int findSecondMinimumValue(TreeNode root) {
        qinaxuDigui(root);

        int count = 0;
        for (Integer integer : set) {

            count++;
            if (count == 2) {
                return integer;
            }
        }
        return -1;
    }

    // 用递归的方法进行先序遍历
    public void qinaxuDigui(TreeNode treeNode) {
        set.add(treeNode.val);
        if (treeNode.left != null) {
            qinaxuDigui(treeNode.left);
        }
        if (treeNode.right != null) {
            qinaxuDigui(treeNode.right);
        }
    }
}
